{extend name="public:base"}
{block name="main"}
<div class="layui-form">
  条件搜索：
  <div class="layui-inline">
    <input class="layui-input" name="start" id="start"  placeholder="请输入开始时间">
  </div>
  <div class="layui-inline">
    <input class="layui-input" name="end" id="end"  placeholder="请输入结束时间">
  </div>
  <div class="layui-inline">
    <input class="layui-input" name="keyword"  placeholder="请输入搜索关键字">
  </div>

  <button class="layui-btn" lay-filter="submit" lay-submit>搜索</button>
  <button class="layui-btn layui-btn-primary"  lay-filter="submit" lay-submit>重置</button>

</div>
<table class="layui-table" lay-data="{height:500,url:location.href, page:true, id:'table'}" lay-filter="table">
  <thead>
    <tr>
      <th lay-data="{field:'actionid',  sort: true}">id</th>
      <th lay-data="{field:'name'}">名称</th>
      <th lay-data="{field:'controller'}">控制器</th>
      <th lay-data="{field:'action'}">操作</th>
      <th lay-data="{field:'type'}">类型</th>
      <th lay-data="{field:'status',templet:'#status'}">状态</th>
      <th lay-data="{field:'addtime'}">添加时间</th>
    </tr>
  </thead>
</table>


<script>
layui.use(['table','laydate','form'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  var form = layui.form;
    laydate.render({
      elem: '#start',
      max: 0
    });
    laydate.render({
      elem: '#end',
      max: 1
   });
   

   //搜索
  form.on('submit(submit)', function(data){
   
    var field=data.field;

    if($(data.elem).html()=="重置"){

        $("input").val("");
        field="";
    }

    table.reload('table', {
       where: field
    });

    return false; 
  });
  
 

  table.on('tool(table)', function(obj){
    return false;
    var data = obj.data;

    if(obj.event === 'del'){
      layer.confirm('真的删除本条数据吗？', function(index){

        $.post("{:Url('actiondel')}",{'actionid': data.actionid},function(data){
           if(data=='1'){
              alert("操作成功~");
              obj.del();
              layer.close(index);
           }else{
             alert("删除失败请重试！");
           }
        })
        
      });
    } else if(obj.event === 'edit'){
        location.href="/admin.php/auth/actioninfo/actionid/"+data.actionid;
    
    }
  });

 
  
  //开关
  form.on('switch(status)', function(data){

    $.post("{:url('actionup')}",{'status':data.elem.checked,'actionid':data.value},function(res){
      if(res=='0'){
        alert("操作失败");
      }
    });
   
  });  

});



</script>


<script type="text/html" id="src">
  <img src='{{d.src}}' width="50px;">
</script>

<script type="text/html" id="status">
  {{#  if(d.status == 1){ }}
    <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" value="{{d.actionid}}" checked>
  {{#  } else { }}
    <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="status"  value="{{d.actionid}}">
  {{#  } }}
</script>

{/block}